<?php

namespace App\Models;

/**
 * Class Code
 * @package App\Models
 */
class Code extends BaseModel
{
    /**
     * 字段
     * @var array
     */
    protected $fillable = [
        'id',
        'name',
        'code',
        'desc'
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function values()
    {
        return $this->hasMany(CodeValue::class, 'code', 'code');
    }

    public static function boot()
    {
        parent::boot();
        static::deleted(function (Code $code) {
            $code->values()->delete();
        });
    }
}
